﻿// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'

Shader "UI/InclineTexture" {
	Properties
	{
		_MainTex("Main Tex", 2D) = "white"{}
		_Diffuse("Diffuse", Color) = (1, 1, 1, 1)
		_Specular("Specular", Color) = (1, 1, 1, 1)
	}
	SubShader
	{
		Tags{ "LightMode" = "ForwardBase" }

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag

			#include "UnityLightingCommon.cginc"
			#include "UnityCG.cginc"

			struct a2v
			{
				float4 vertex : POSITION;
				float4 normal : NORMAL;
				float4 texcoord : TEXCOORD0;
			};

			struct v2f
			{
				float4 vertex : SV_POSITION;
				fixed3 world_normal : TEXCOORD0;
				fixed3 world_pos : TEXCOORD1;
				float2 uv : TEXCOORD2;
			};

			fixed4 _Diffuse;
			sampler2D _MainTex;
			float4 _MainTex_ST;

			v2f vert(a2v v)
			{
				v2f o;
				o.vertex = UnityObjectToClipPos(v.vertex);
				o.world_normal = normalize(UnityObjectToWorldNormal(v.normal));
				o.world_pos = mul(unity_ObjectToWorld, v.vertex).xyz;
				o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);//v.texcoord.xy * _MainTex_ST.xy + _MainTex_ST.zw;
				return o;
			}

			fixed4 frag(v2f i) : SV_Target
			{
				fixed3 albedo = tex2D(_MainTex, i.uv).rgb * _Diffuse.rgb;
				fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.xyz * albedo;
				fixed3 worldLight = normalize(UnityWorldSpaceLightDir(i.world_pos));
				fixed3 diffuse = _LightColor0.rgb * _Diffuse.rgb * pow(dot(i.world_normal, worldLight) + 1, 3) / 8;

				fixed3 viewDir = normalize(_WorldSpaceCameraPos.xyz - i.world_pos.xyz);
				fixed3 halfDir = normalize(worldLight + viewDir);

				return fixed4(ambient + diffuse, 1.0);
			}
			ENDCG
		}
	}
	FallBack "Specular"
}
